package com.gz.spring.aop.aspectj;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.junit.jupiter.api.Order;
import org.springframework.stereotype.Component;

import java.util.Arrays;
import java.util.List;

@Order(2)
@Aspect
@Component
public class FuncAspect2 {

    //AOP环绕通知
    @Around(value = "execution(public float com.gz.spring.aop.aspectj.Func.getSub(float,float))||" +
            "execution(public float com.gz.spring.aop.aspectj.Func.getSum(float,float))")
    public Object doAround(ProceedingJoinPoint jointPoint){
        String methodName = jointPoint.getSignature().getName();
        Object result=null;
        try {
            Object[] args = jointPoint.getArgs();
            List<Object> list = Arrays.asList(args);
            System.out.println("AOP环绕通知--"+methodName+"方法开始--参数:"+list);
            //通过jointPoint.proceed()执行方法
            result = jointPoint.proceed();
            System.out.println("AOP环绕通知--"+methodName+"方法结束--结果是:"+result);
        } catch (Throwable e) {
            e.printStackTrace();
            System.out.println("AOP环绕通知--"+methodName+"方法抛出异常:"+e);
        } finally {
            System.out.println("AOP环绕通知--"+methodName+"方法最终结束");
        }
        return result;
    }
}
